﻿using BusinessEntity.CGManage;
using BusinessRepository;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading.Tasks;

namespace BusinessRule.Purchase
{
    public class CGGL_CG
    {
        #region "采购计划"

        //列表页面
        public static async Task<(IEnumerable<dynamic>, int)> GetCG_Project(CG_ProjectQuerry querry)
        {
            string str = "and   1=1 ";
            if (!string.IsNullOrEmpty(querry.jhcgbm) && querry.jhcgbm != "string")
            {
                str += "and jhcgbm like '%" + querry.jhcgbm + "%'";
            }
            if (!string.IsNullOrEmpty(querry.jhcgmc) && querry.jhcgmc != "string")
            {
                str += "and jhcgmc like '%" + querry.jhcgmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cglb) && querry.cglb != "string")
            {
                str += " and cglb = '" + querry.cglb + "'";
            }
            if (!string.IsNullOrEmpty(querry.jycgfs) && querry.jycgfs != "string")
            {
                str += " and jycgfs='" + querry.jycgfs + "'";
            }
            if (!string.IsNullOrEmpty(querry.jyzbfs) && querry.jyzbfs != "string")
            {
                str += " and jyzbfs='" + querry.jyzbfs + "'";
            }
            if (!string.IsNullOrEmpty(querry.cznd) && querry.cznd != "string")
            {
                str += " and cznd = '" + querry.cznd + "'";
            }
            if (!string.IsNullOrEmpty(querry.zjly) && querry.zjly != "string")
            {
                str += " and zjly = '" + querry.zjly + "'";
            }
            if (querry.ysje1 != null||querry.ysje2 != null)
            {
                if (querry.ysje2 >= querry.ysje1)
                {

                    str += " and (ysje between '" + querry.ysje1 + "' and '" + querry.ysje2 + "')";
                }
                else
                {
                    str += " and (ysje between 0 and 0)";
                }
            }
            if (!string.IsNullOrEmpty(querry.xqdw) && querry.xqdw != "string")
            {
                str += " and xqdw = '" + querry.xqdw + "'";
            }
            if (!string.IsNullOrEmpty(querry.xqbm) && querry.xqbm != "string")
            {
                str += " and xqbm = '" + querry.xqbm + "'";
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                string status = "";
                if (querry.zt == "待提交")
                {
                    status = "1";
                }
                else if (querry.zt == "已驳回")
                {
                    status = "4";

                }
                else if (querry.zt == "已作废")
                {
                    status = "5";

                }
                else if (querry.zt == "待审核")
                {
                    status = "2";

                }
                else if (querry.zt == "审核中")
                {
                    status = "9";

                }
                else if (querry.zt == "已通过")
                {
                    status = "3";

                }
               
                else
                {
                    status = "0";
                }
                str += " and zt = '" + status + "'";
            }
            string sql = @"select ListID,jhcgbm,jhcgmc,cglb,cznd,zjly,ysje,sfcgjksp,sflscg,xqdw,xqbm,tjr,tjsj,zt from pur_project where (bmdm in " + querry.DepartID + " )" + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);
        }

        //获取详情
        public static async Task<DataTable> GetCG_Project_Detail(string jhcgbm)
        {
            
           
            string  sql = "select jhcgbm, jhcgmc, cznd, cglb, zjly, ysje, sfcgjksp, sflscg, xqdw, xqbm, ywdjr, lxdh, ncsj, cgsm, bmdm, tjr, tjsj from pur_project where jhcgbm='" + jhcgbm + "' ;";
         
            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        //删除采购计划
        public static async Task DeleteCG_Project(string strid)
        {

            string sql = "delete pur_project where jhcgbm in ("+strid+") ";


            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }

        //新增、修改采购计划
        public static async Task InsertCG_Project(CG_Project_Detail cgjh)
        {
          
            string sql = "";
            if (cgjh.listid == "1")
            {
                sql = @"insert into pur_project (  jhcgbm,jhcgmc,cznd,cglb,zjly,ysje,sfcgjksp,sflscg,xqdw,xqbm,ywdjr,lxdh,ncsj,cgsm,bmdm,tjr,tjsj,zt)
values(  '"+cgjh.jhcgbm+"','"+cgjh.jhcgmc+"','"+cgjh.cznd+"','"+cgjh.cglb+"','"+cgjh.zjly+"','"+cgjh.ysje+"','"+cgjh.sfcgjksp+"','"+cgjh.sflscg+"','"+cgjh.xqdw+"','"+cgjh.xqbm+"','"+cgjh.ywdjr+"','"+cgjh.lxdh+"','"+cgjh.ncsj+"','"+cgjh.cgsm+"','"+cgjh.bmdm+"','"+cgjh.tjr+"','"+cgjh.tjsj+"','"+cgjh.zt+"' );  ";
              
            }
            else
            {
                sql = "update pur_project set  jhcgmc='"+cgjh.jhcgmc + "',cznd='"+cgjh.cznd + "',cglb='"+cgjh.cglb + "',zjly='"+cgjh.zjly + "',ysje='"+cgjh.ysje + "',sfcgjksp='"+cgjh.sfcgjksp + "',sflscg='"+cgjh.sflscg + "',xqdw='"+cgjh.xqdw + "',xqbm='"+cgjh.xqbm + "',ywdjr='"+cgjh.ywdjr + "',lxdh='"+cgjh.lxdh + "',ncsj='"+cgjh.ncsj + "',cgsm='"+cgjh.cgsm + "',bmdm='"+cgjh.bmdm + "',tjr='"+cgjh.tjr + "',tjsj='"+cgjh.tjsj + "',zt='"+cgjh.zt+"'  where jhcgbm='" + cgjh.jhcgbm + "'  ; ";
                
            }
            sql += "update pur_project set ncsj=null where jhcgbm='"+cgjh.jhcgbm+ "' and  ncsj='1900-01-01 00:00:00.000' ";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }
        //审批回调
        public static async Task UpdateCG_Projectzt(string jhcgbm,string zt)
        {

            string sql = "update pur_project set zt='"+zt+"' where jhcgbm='"+jhcgbm+"' ";
           

            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }

        #endregion

        #region"采购立项"
        //列表页面
        public static async Task<(IEnumerable<dynamic>, int)> GetCG_Approval(CG_ApprovalQuerry querry)
        {
            string str = "and   1=1 ";
            if (!string.IsNullOrEmpty(querry.cgxmbm) && querry.cgxmbm != "string")
            {
                str += "and cgxmbm like '%" + querry.cgxmbm + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cgxmmc) && querry.cgxmmc != "string")
            {
                str += "and cgxmmc like '%" + querry.cgxmmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cglb) && querry.cglb != "string")
            {
                str += " and cglb = '" + querry.cglb + "'";
            }
            if (!string.IsNullOrEmpty(querry.zzfs) && querry.zzfs != "string")
            {
                str += " and zzfs='" + querry.zzfs + "'";
            }
            if (!string.IsNullOrEmpty(querry.zbfs) && querry.zbfs != "string")
            {
                str += " and zbfs='" + querry.zbfs + "'";
            }
            if (!string.IsNullOrEmpty(querry.cznd) && querry.cznd != "string")
            {
                str += " and cznd = '" + querry.cznd + "'";
            }

            if (!string.IsNullOrEmpty(querry.xqdw) && querry.xqdw != "string")
            {
                str += " and xqdw = '" + querry.xqdw + "'";
            }
            if (!string.IsNullOrEmpty(querry.xqbm) && querry.xqbm != "string")
            {
                str += " and xqbm = '" + querry.xqbm + "'";
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                string status = "";
                if (querry.zt == "待提交")
                {
                    status = "1";
                }
                else if (querry.zt == "已驳回")
                {
                    status = "4";

                }
                else if (querry.zt == "已作废")
                {
                    status = "5";

                }
                else if (querry.zt == "待审核")
                {
                    status = "2";

                }
                else if (querry.zt == "审核中")
                {
                    status = "9";

                }
                else if (querry.zt == "已通过")
                {
                    status = "3";

                }

                else
                {
                    status = "0";
                }
                str += " and zt = '" + status + "'";
            }
            string sql = @"select ListID,cgxmbm,cgxmmc,cglb,zzfs,zbfs,yjcgzje,xqdw,xqbm,tjr,tjsj,zt from pur_approval where (bmdm in " + querry.DepartID + " )" + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);
        }
        //选择采购计划
        public static async Task<(IEnumerable<dynamic>, int)> SelectCG_Project(CG_ProjectQuerry querry)
        {
            string str = "and   1=1 ";
            if (!string.IsNullOrEmpty(querry.jhcgbm) && querry.jhcgbm != "string")
            {
                str += "and jhcgbm like '%" + querry.jhcgbm + "%'";
            }
            if (!string.IsNullOrEmpty(querry.jhcgmc) && querry.jhcgmc != "string")
            {
                str += "and jhcgmc like '%" + querry.jhcgmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cglb) && querry.cglb != "string")
            {
                str += " and cglb = '" + querry.cglb + "'";
            }
           
            if (!string.IsNullOrEmpty(querry.cznd) && querry.cznd != "string")
            {
                str += " and cznd = '" + querry.cznd + "'";
            }
            if (!string.IsNullOrEmpty(querry.zjly) && querry.zjly != "string")
            {
                str += " and zjly = '" + querry.zjly + "'";
            }
            
            if (!string.IsNullOrEmpty(querry.xqdw) && querry.xqdw != "string")
            {
                str += " and xqdw = '" + querry.xqdw + "'";
            }
            if (!string.IsNullOrEmpty(querry.xqbm) && querry.xqbm != "string")
            {
                str += " and xqbm = '" + querry.xqbm + "'";
            }

            string sql = "  select * from vw_pur_project where kyysje>0 and zt='3' and (bmdm in " + querry.DepartID + " ) " + str;

            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);

        }


        //获取详情
        public static async Task<DataTable> GetCG_Approval_cgjh(string cgxmbm)
        {


            string sql = "select jhcgbm,jhcgmc,cglb,cznd,zjly,ysje, kyysje,xqdw,xqbm from vw_pur_project where jhcgbm=(select jhcgbm  from  pur_approval where cgxmbm='" + cgxmbm+"' ) ;";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> GetCG_Approval_xmxx(string cgxmbm)
        {


            string sql = "select cgxmbm, cgxmmc, jhcgbm, cglb, zjly, yjcgzje, xmqdrq, cznd, zzfs, zbfs, pbbf, xqdw, xqbm, lxr, lxdh, cgnr, bz, tjr, tjsj, bmdm,cgfs from pur_approval where cgxmbm='" + cgxmbm + "' ;";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> GetCG_Approval_wpmx(string cgxmbm)
        {


            string sql = "select * from pur_approval_goods where cgxmbm='" + cgxmbm + "' ;";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        //新增、修改采购立项
        public static async Task InsertCG_Approval_Xm(CG_Approval cg)
        {

            string sql = "";
            if (cg.xmxx.listid == "1")
            {
                sql = @"insert into pur_approval(cgxmbm,cgxmmc,jhcgbm,cglb,zjly,yjcgzje,xmqdrq,cznd,zzfs,cgfs,zbfs,pbbf,xqdw,xqbm,lxr,lxdh,cgnr,bz,tjr,tjsj,bmdm,zt) values ('" + cg.xmxx.cgxmbm+"','"+cg.xmxx.cgxmmc+"','"+cg.xmxx.jhcgbm+"','"+cg.xmxx.cglb+"','"+cg.xmxx.zjly+"','"+cg.xmxx.yjcgzje+"','"+cg.xmxx.xmqdrq+"','"+cg.xmxx.cznd+"','"+cg.xmxx.zzfs+"','"+cg.xmxx.cgfs+"','"+cg.xmxx.zbfs+"','"+cg.xmxx.pbbf+"','"+cg.xmxx.xqdw+"','"+cg.xmxx.xqbm+"','"+cg.xmxx.lxr+"','"+cg.xmxx.lxdh+"','"+cg.xmxx.cgnr+"','"+cg.xmxx.bz+"','"+cg.xmxx.tjr+"','"+cg.xmxx.tjsj+"','"+cg.xmxx.bmdm+"','"+cg.xmxx.zt+"');  ";


            }
            else
            {
                sql = "update pur_approval set  cgxmmc='"+cg.xmxx.cgxmmc + "',jhcgbm='"+cg.xmxx.jhcgbm + "',cglb='"+cg.xmxx.cglb + "',zjly='"+cg.xmxx.zjly + "',yjcgzje='"+cg.xmxx.yjcgzje + "',xmqdrq='"+cg.xmxx.xmqdrq + "',cznd='"+cg.xmxx.cznd + "',zzfs='"+cg.xmxx.zzfs + "',cgfs='"+cg.xmxx.cgfs+"',zbfs='"+cg.xmxx.zbfs + "',pbbf='"+cg.xmxx.pbbf + "',xqdw='"+cg.xmxx.xqdw + "',xqbm='"+cg.xmxx.xqbm + "',lxr='"+cg.xmxx.lxr + "',lxdh='"+cg.xmxx.lxdh + "',cgnr='"+cg.xmxx.cgnr + "',bz='"+cg.xmxx.bz + "',tjr='"+cg.xmxx.tjr + "',tjsj='"+cg.xmxx.tjsj + "',bmdm='"+cg.xmxx.bmdm + "',zt='"+cg.xmxx.zt+ "'  where cgxmbm='" + cg.xmxx.cgxmbm + "'  ; ";

            }
            sql += "update pur_approval set xmqdrq=null where  xmqdrq='1900-01-01 00:00:00.000' and cgxmbm='" + cg.xmxx.cgxmbm+"'";
            await DeleteCG_Approval_Goods(cg.xmxx.cgxmbm);
            foreach (CG_Approval_Goods wpmx in cg.wpmx)
            {
                await InsertCG_Approval_Goods(wpmx, cg.xmxx.cgxmbm);
            }
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }

        public static async Task DeleteCG_Approval_Goods(string cgxmbm)
        {

            string sql = "delete pur_approval_goods where cgxmbm='"+ cgxmbm + "'; ";


            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }

        public static async Task InsertCG_Approval_Goods(CG_Approval_Goods wpmx,string cgxmbm)
        {

            string sql = "insert into pur_approval_goods(cgxmbm,cgpm,wpmc,ggxh,jldw,dj,sl,je) values('"+cgxmbm+"','"+wpmx.cgpm + "','" + wpmx.wpmc + "','" + wpmx.ggxh + "','" + wpmx.jldw + "','" + wpmx.dj + "','" + wpmx.sl + "','" + wpmx.je + "') ; ";


            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }
        //删除采购立项
        public static async Task DeleteCG_Approval(string strid)
        {

            string sql = "delete pur_approval where cgxmbm in (" + strid + ") ; " ;
            sql += "delete pur_approval_goods where cgxmbm in (" + strid + ") ; ";

            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }


        //审批回调
        public static async Task UpdateCG_Approvalzt(string cgxmbm, string zt)
        {

            string sql = "update pur_approval set zt='" + zt + "' where cgxmbm='" + cgxmbm + "' ";


            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }
        #endregion

        #region"代理机构申请"

        //列表页面
        public static async Task<(IEnumerable<dynamic>, int)> GetCG_Agency(CG_AgencyQuerry querry)
        {
            string str = "and   1=1 ";
            if (!string.IsNullOrEmpty(querry.djbm) && querry.djbm != "string")
            {
                str += "and djbm like '%" + querry.djbm + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cgxmbm) && querry.cgxmbm != "string")
            {
                str += "and cgxmbm like '%" + querry.cgxmbm + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cgxmmc) && querry.cgxmmc != "string")
            {
                str += "and cgxmmc like '%" + querry.cgxmmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.dljg) && querry.dljg != "string")
            {
                str += "and dljgmc like '%" + querry.dljg + "%'";
            }

           
            if (!string.IsNullOrEmpty(querry.xqdw) && querry.xqdw != "string")
            {
                str += " and xqdw = '" + querry.xqdw + "'";
            }
            if (querry.tjsj1 != null && querry.tjsj2 != null)
            {
                if (querry.tjsj2 >= querry.tjsj1)
                {
                    //DateTime sqjsrq = Convert.ToDateTime(querry.sqjsrq);
                    //string jsrq = sqjsrq.ToString("yyyyMMdd");
                    //DateTime sqksrq = Convert.ToDateTime(querry.sqksrq);
                    //string ksrq = sqksrq.ToString("yyyyMMdd");
                    str += " and (tjsj between '"+querry.tjsj1+"' and '"+querry.tjsj2+"')";
                }
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                string status = "";
                if (querry.zt == "待提交")
                {
                    status = "1";
                }
                else if (querry.zt == "已驳回")
                {
                    status = "4";

                }
                else if (querry.zt == "已作废")
                {
                    status = "5";

                }
                else if (querry.zt == "待审核")
                {
                    status = "2";

                }
                else if (querry.zt == "审核中")
                {
                    status = "9";

                }
                else if (querry.zt == "已通过")
                {
                    status = "3";

                }

                else
                {
                    status = "0";
                }
                str += " and zt = '" + status + "'";
            }
            string sql = @"select * from vw_pur_agency where (bmdm in " + querry.DepartID + " )" + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);
        }

        //获取详情
        public static async Task<DataTable> GetCG_Agency_cgxm(string djbm)
        {


            string sql = "select cgxmbm,cgxmmc,cglb,zjly,yjcgzje,zzfs,cgfs,zbfs,xqdw,xqbm from  pur_approval  where cgxmbm=(select cgxmbm from pur_agency where djbm='"+djbm+"') ;";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> GetCG_Agency_dljg(string djbm)
        {


            string sql = "select djbm, cgxmbm, dljgmc, dljgclsj, sfcjgqjxm, sfytssxcl, sm, tjr, tjsj,bmdm from pur_agency where djbm='" + djbm + "' ;";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }


        //选择采购项目
        public static async Task<(IEnumerable<dynamic>, int)> SelectCG_Approval(CG_ApprovalQuerry querry)
        {
            string str = "";
            if (querry.type =="agency")
            {
                 str = "and   zt='3' and cgxmbm not in ( select cgxmbm from pur_agency) and zbfs<>'直接采购'";
            }
            if (querry.type == "lot")
            {
                str = "and  zt='3' and (yjcgzje <50000 or cgxmbm in(select cgxmbm from pur_agency where zt='3' )) and cgxmbm not in(select cgxmbm from pur_lot_list)";
            }
            if (!string.IsNullOrEmpty(querry.cgxmbm) && querry.cgxmbm != "string")
            {
                str += "and cgxmbm like '%" + querry.cgxmbm + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cgxmmc) && querry.cgxmmc != "string")
            {
                str += "and cgxmmc like '%" + querry.cgxmmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cglb) && querry.cglb != "string")
            {
                str += " and cglb = '" + querry.cglb + "'";
            }
            if (!string.IsNullOrEmpty(querry.zjly) && querry.zjly != "string")
            {
                str += " and zjly = '" + querry.zjly + "'";
            }
            if (!string.IsNullOrEmpty(querry.zzfs) && querry.zzfs != "string")
            {
                str += " and zzfs='" + querry.zzfs + "'";
            }
            if (!string.IsNullOrEmpty(querry.cgfs) && querry.cgfs != "string")
            {
                str += " and cgfs='" + querry.cgfs + "'";
            }
            if (!string.IsNullOrEmpty(querry.zbfs) && querry.zbfs != "string")
            {
                str += " and zbfs='" + querry.zbfs + "'";
            }
            
            if (!string.IsNullOrEmpty(querry.xqdw) && querry.xqdw != "string")
            {
                str += " and xqdw = '" + querry.xqdw + "'";
            }
            if (!string.IsNullOrEmpty(querry.xqbm) && querry.xqbm != "string")
            {
                str += " and xqbm = '" + querry.xqbm + "'";
            }

            string     sql = "  select listid,cgxmbm,cgxmmc,cglb,zjly,yjcgzje,zzfs,cgfs,zbfs,xqdw,xqbm from  pur_approval where  (bmdm in " + querry.DepartID + " ) " + str;
          
            //if (querry.type == "lot")
            //{
            //    sql = "  select listid,cgxmbm,cgxmmc,cglb,zjly,yjcgzje,zzfs,cgfs,zbfs,xqdw,xqbm from  pur_approval where  (bmdm in " + querry.DepartID + " ) " + str;
            //}
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);

        }

        //新增、修改代理机构
        public static async Task InsertCG_Agency(CG_Agency cg)
        {

            string sql = "";
            if (cg.listid == "1")
            {
                sql = @"insert into pur_agency(djbm,cgxmbm,dljgmc,dljgclsj,sfcjgqjxm,sfytssxcl,sm,tjr,tjsj,zt,bmdm) values ('"+cg.djbm+"','"+cg.cgxmbm+"','"+cg.dljgmc+"','"+cg.dljgclsj+"','"+cg.sfcjgqjxm+"','"+cg.sfytssxcl+"','"+cg.sm+"','"+cg.tjr+"','"+cg.tjsj+"','"+cg.zt+"','"+cg.bmdm+"');  ";


            }
            else
            {
                sql = "update pur_agency set cgxmbm='"+cg.cgxmbm + "',dljgmc='"+cg.dljgmc + "',dljgclsj='"+cg.dljgclsj + "',sfcjgqjxm='"+cg.sfcjgqjxm + "',sfytssxcl='"+cg.sfytssxcl + "',sm='"+cg.sm + "',tjr='"+cg.tjr + "',tjsj='"+cg.tjsj + "',zt='"+cg.zt + "',bmdm='"+cg.bmdm+"'  where djbm='" + cg.djbm + "'  ; ";

            }
            sql += "update pur_agency set dljgclsj=null where djbm='" + cg.djbm + "' and  dljgclsj='1900-01-01 00:00:00.000' ";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }

        //删除代理机构
        public static async Task DeleteCG_Agency(string strid)
        {

            string sql = "delete pur_agency where djbm in (" + strid + ") ; ";
          

            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }

        //审批回调
        public static async Task UpdateCG_Agencyzt(string djbm, string zt)
        {

            string sql = "update pur_agency set zt='" + zt + "' where djbm='" + djbm + "' ";


            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }

        //获取代理机构名称（下拉框）
        public static async Task<DataTable> GetCG_AgencyName()
        {


            string sql = "select agencyid,agencyname from  pur_agencyname  ;";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        #endregion

        #region"标段拆分"

        //列表页面
        public static async Task<(IEnumerable<dynamic>, int)> GetCG_Lot(CG_LotQuerry querry)
        {
            string str = "and   1=1 ";
            if (!string.IsNullOrEmpty(querry.djbm) && querry.djbm != "string")
            {
                str += "and djbm like '%" + querry.djbm + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cgxmbm) && querry.cgxmbm != "string")
            {
                str += "and cgxmbm like '%" + querry.cgxmbm + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cgxmmc) && querry.cgxmmc != "string")
            {
                str += "and cgxmmc like '%" + querry.cgxmmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cglb) && querry.cglb != "string")
            {
                str += "and cglb = '" + querry.cglb + "'";
            }


            if (!string.IsNullOrEmpty(querry.xqdw) && querry.xqdw != "string")
            {
                str += " and xqdw = '" + querry.xqdw + "'";
            }
            if (querry.tjsj1 != null && querry.tjsj2 != null)
            {
                if (querry.tjsj2 >= querry.tjsj1)
                {
                    //DateTime sqjsrq = Convert.ToDateTime(querry.sqjsrq);
                    //string jsrq = sqjsrq.ToString("yyyyMMdd");
                    //DateTime sqksrq = Convert.ToDateTime(querry.sqksrq);
                    //string ksrq = sqksrq.ToString("yyyyMMdd");
                    str += " and (tjsj between '" + querry.tjsj1 + "' and '" + querry.tjsj2 + "')";
                }
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                string status = "";
                if (querry.zt == "待提交")
                {
                    status = "1";
                }
                else if (querry.zt == "已驳回")
                {
                    status = "4";

                }
                else if (querry.zt == "已作废")
                {
                    status = "5";

                }
                else if (querry.zt == "待审核")
                {
                    status = "2";

                }
                else if (querry.zt == "审核中")
                {
                    status = "9";

                }
                else if (querry.zt == "已通过")
                {
                    status = "3";

                }

                else
                {
                    status = "0";
                }
                str += " and zt = '" + status + "'";
            }
            string sql = @"select * from vw_pur_lot where (bmdm in " + querry.DepartID + " )" + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);
        }

        //获取详情
        public static async Task<DataTable> GetCG_Lot_cgxm(string djbm)
        {


            string sql = "select cgxmbm,cgxmmc,cglb,zjly,yjcgzje,zzfs,cgfs,zbfs,xqdw,xqbm from  pur_approval  where cgxmbm=(select cgxmbm from pur_lot_list where djbm='" + djbm + "') ;";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> GetCG_Lot_list(string djbm)
        {


            string sql = "select djbm, cgxmbm, cgxmmc, bds, tjr, tjsj, bmdm from pur_lot_list  where  djbm='" + djbm + "' ;";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> GetCG_Lot_detail(string djbm)
        {


            string sql = "select * from pur_lot where cgxmbm=(select cgxmbm from pur_lot_list where djbm='"+djbm+"') ;";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        //选择采购项目
        public static async Task<(IEnumerable<dynamic>, int)> SelectCG_Approval_lot(CG_ApprovalQuerry querry)
        {
            string str = "and  zt='3' and (yjcgzje <50000 or cgxmbm in(select cgxmbm from pur_agency where zt='3' )) and cgxmbm not in(select cgxmbm from pur_lot_list)";
            if (!string.IsNullOrEmpty(querry.cgxmbm) && querry.cgxmbm != "string")
            {
                str += "and cgxmbm like '%" + querry.cgxmbm + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cgxmmc) && querry.cgxmmc != "string")
            {
                str += "and cgxmmc like '%" + querry.cgxmmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cglb) && querry.cglb != "string")
            {
                str += " and cglb = '" + querry.cglb + "'";
            }
            if (!string.IsNullOrEmpty(querry.zjly) && querry.zjly != "string")
            {
                str += " and zjly = '" + querry.zjly + "'";
            }
            if (!string.IsNullOrEmpty(querry.zzfs) && querry.zzfs != "string")
            {
                str += " and zzfs='" + querry.zzfs + "'";
            }
            if (!string.IsNullOrEmpty(querry.cgfs) && querry.cgfs != "string")
            {
                str += " and cgfs='" + querry.cgfs + "'";
            }
            if (!string.IsNullOrEmpty(querry.zbfs) && querry.zbfs != "string")
            {
                str += " and zbfs='" + querry.zbfs + "'";
            }

            if (!string.IsNullOrEmpty(querry.xqdw) && querry.xqdw != "string")
            {
                str += " and xqdw = '" + querry.xqdw + "'";
            }
            if (!string.IsNullOrEmpty(querry.xqbm) && querry.xqbm != "string")
            {
                str += " and xqbm = '" + querry.xqbm + "'";
            }

            string sql = "  select listid,cgxmbm,cgxmmc,cglb,zjly,yjcgzje,zzfs,cgfs,zbfs,xqdw,xqbm from  pur_approval where  (bmdm in " + querry.DepartID + " ) " + str;

            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);

        }


        //新增、修改标段
        public static async Task InsertCG_Lot(CG_Lot cg)
        {

            string sql = "";
            if (cg.list.listid == "1")
            {
                sql = @"insert into pur_lot_list(djbm,cgxmbm,cgxmmc,bds,tjr,tjsj,zt,bmdm) values ('"+cg.list.djbm+ "','" + cg.list.cgxmbm + "','" + cg.list.cgxmmc + "','" + cg.list.bds + "','" + cg.list.tjr + "','" + cg.list.tjsj + "','" + cg.list.zt + "','" + cg.list.bmdm + "');  ";


            }
            else
            {
                sql = "update pur_lot_list set cgxmbm='" + cg.list.cgxmbm + "',cgxmmc='" + cg.list.cgxmmc + "',bds='" + cg.list.bds + "',tjr='" + cg.list.tjr + "',tjsj='" + cg.list.tjsj + "',zt='" + cg.list.zt + "',bmdm='" + cg.list.bmdm + "'    where djbm='" + cg.list.djbm + "'  ; ";

            }
            await DeleteCG_Lot_split(cg.list.cgxmbm);
            foreach (CG_Lot_split bd in cg.split)
            {
                await InsertCG_Lot_split(bd, cg.list.cgxmbm,cg.list.cgxmmc);
            }
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }

        public static async Task DeleteCG_Lot_split(string cgxmbm)
        {

            string sql = "delete pur_lot where cgxmbm='" + cgxmbm + "'; ";


            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }

        public static async Task InsertCG_Lot_split(CG_Lot_split bd, string cgxmbm,string cgxmmc)
        {
            string bdid = cgxmbm + "0" + bd.xh.ToString();
            string sql = "insert into pur_lot(bdid,cgxmbm,cgxmmc,bdmc,bdje,bdsm,xh) values('"+bdid+"','"+cgxmbm+"','"+cgxmmc+"','"+bd.bdmc+"','"+bd.bdje+"','"+bd.bdsm+"','"+bd.xh+"') ; ";


            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }

        //删除采购立项
        public static async Task DeleteCG_Lot(string strid)
        {

            string sql = "delete pur_lot_list where cgxmbm in (" + strid + ") ; ";
            sql += "delete pur_lot where cgxmbm in (" + strid + ") ; ";

            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }


        //审批回调
        public static async Task UpdateCG_Lotzt(string djbm, string zt)
        {

            string sql = "update pur_lot_list set zt='" + zt + "' where djbm='" + djbm + "' ";


            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }
        #endregion

        #region"招标申请"
        //列表页面
        public static async Task<(IEnumerable<dynamic>, int)> GetCG_Invite(CG_InviteQuerry querry)
        {
            string str = "and   1=1 ";
            if (!string.IsNullOrEmpty(querry.zbmc) && querry.zbmc != "string")
            {
                str += "and zbmc like '%" + querry.zbmc + "%'";
            }
            if (querry.ysje1 != null || querry.ysje2 != null)
            {
                if (querry.ysje2 >= querry.ysje1)
                {

                    str += " and (ysje between '" + querry.ysje1 + "' and '" + querry.ysje2 + "')";
                }
                else
                {
                    str += " and (ysje between 0 and 0)";
                }
            }
            if (!string.IsNullOrEmpty(querry.cgxmmc) && querry.cgxmmc != "string")
            {
                str += "and cgxmmc like '%" + querry.cgxmmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cgfs) && querry.cgfs != "string")
            {
                str += "and cgfs = '" + querry.cgfs + "'";
            }


            if (!string.IsNullOrEmpty(querry.zbfs) && querry.zbfs != "string")
            {
                str += " and zbfs = '" + querry.zbfs + "'";
            }
            if (!string.IsNullOrEmpty(querry.bdmc) && querry.bdmc != "string")
            {
                str += "and bdmc like '%" + querry.bdmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                string status = "";
                if (querry.zt == "待提交")
                {
                    status = "1";
                }
                else if (querry.zt == "已驳回")
                {
                    status = "4";

                }
                else if (querry.zt == "已作废")
                {
                    status = "5";

                }
                else if (querry.zt == "待审核")
                {
                    status = "2";

                }
                else if (querry.zt == "审核中")
                {
                    status = "9";

                }
                else if (querry.zt == "已通过")
                {
                    status = "3";

                }

                else
                {
                    status = "0";
                }
                str += " and zt = '" + status + "'";
            }
            string sql = @"select * from vw_pur_invite where (bmdm in " + querry.DepartID + " )" + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);
        }

        
        //获取详情
        public static async Task<DataTable> GetCG_Invite_bdxx(string djbm)
        {


            string sql = "select a.bdmc,a.bdje,b.cgxmbm,b.cgxmmc,b.cglb,b.zzfs,b.cgfs,b.zbfs,b.xqdw,b.xqbm from pur_lot a inner join pur_approval b on a.cgxmbm=b.cgxmbm and a.bdid=(select bdid from pur_invite where djbm='"+djbm+"' ) ;";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> GetCG_Invite_zbxx(string djbm)
        {


            string sql = "select djbm, cgxmbm, bdid, bdmc, zbmc, ysje, zbfs, pbbf, zbrq, dlzjjg, zbfzr, lxdh, tjr, tjsj, bmdm, zbjd, zbsm from pur_invite where djbm='"+djbm+"' ;";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }


        //选择标段
        public static async Task<(IEnumerable<dynamic>, int)> SelectCG_Lot(CG_LotQuerry querry)
        {
            string str = "and  1=1 ";
           
            if (!string.IsNullOrEmpty(querry.cgxmmc) && querry.cgxmmc != "string")
            {
                str += "and cgxmmc like '%" + querry.cgxmmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.bdmc) && querry.bdmc != "string")
            {
                str += "and bdmc like '%" + querry.bdmc + "%'";
            }

            if (querry.bdje1 != null && querry.bdje2 != null)
            {
                if (querry.bdje2 > querry.bdje1)
                {

                    str += " and (bdje between '" + querry.bdje1 + "' and '" + querry.bdje2 + "')";
                }
            }
            if (!string.IsNullOrEmpty(querry.cgfs) && querry.cgfs != "string")
            {
                str += " and cgfs = '" + querry.cgfs + "'";
            }
            if (!string.IsNullOrEmpty(querry.zbfs) && querry.zbfs != "string")
            {
                str += " and zbfs = '" + querry.zbfs + "'";
            }
            

            if (!string.IsNullOrEmpty(querry.xqdw) && querry.xqdw != "string")
            {
                str += " and xqdw = '" + querry.xqdw + "'";
            }
            if (!string.IsNullOrEmpty(querry.xqbm) && querry.xqbm != "string")
            {
                str += " and xqbm = '" + querry.xqbm + "'"; 
            }

            string sql = "  select * from  vw_pur_lot_invite where  (bmdm in " + querry.DepartID + " ) " + str;

            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);

        }

        //新增、修改招标申请
        public static async Task InsertCG_Invite(CG_Invite zb)
        {

            string sql = "";
            if (zb.listid == "1")
            {
                sql = @"insert into pur_invite(djbm, cgxmbm, bdid, bdmc, zbmc, ysje, zbfs, pbbf, zbrq, dlzjjg, zbfzr, lxdh, tjr, tjsj, zt, bmdm, zbsm) values ('"+zb.djbm+"','"+zb. cgxmbm+"','"+zb. bdid+"','"+zb. bdmc+"','"+zb. zbmc+"','"+zb. ysje+"','"+zb. zbfs+"','"+zb. pbbf+"','"+zb. zbrq+"','"+zb. dlzjjg+"','"+zb. zbfzr+"','"+zb. lxdh+"','"+zb. tjr+"','"+zb. tjsj+"','"+zb. zt+"','"+zb. bmdm+"','"+zb. zbsm+"');  ";


            }
            else
            {
                sql = "update pur_invite set  cgxmbm='" + zb.cgxmbm + "', bdid='"+zb.bdid + "', bdmc='"+zb.bdmc + "', zbmc='"+zb.zbmc + "', ysje='"+zb.ysje + "', zbfs='"+zb.zbfs + "', pbbf='"+zb.pbbf + "', zbrq='"+zb.zbrq + "', dlzjjg='"+zb.dlzjjg + "', zbfzr='"+zb.zbfzr + "', lxdh='"+zb.lxdh + "', tjr='"+zb.tjr + "', tjsj='"+zb.tjsj + "', zt='"+zb.zt + "', bmdm='"+zb.bmdm + "', zbsm='"+zb.zbsm+"'  where djbm='" + zb.djbm + "'  ; ";

            }
            sql += "update pur_invite set zbrq=null where  zbrq='1900-01-01 00:00:00.000' and djbm='"+zb.djbm+"' ";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }

        //删除
        public static async Task DeleteCG_Invite(string strid)
        {

            string sql = "delete pur_invite where djbm in (" + strid + ") ; ";
           
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }


        //审批回调
        public static async Task UpdateCG_Invitezt(string djbm, string zt)
        {

            string sql = "update pur_invite set zt='" + zt + "' where djbm='" + djbm + "' ";
            if (zt == "3")
            {
                sql += "update pur_invite set zbjd='招标中' where bdid=(select bdid from pur_bidder where djbm='" + djbm + "') ";
            }
           else
            {
                sql += "update pur_invite set zbjd=null where bdid=(select bdid from pur_bidder where djbm='" + djbm + "') ";
            }

            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }
        #endregion

        #region
        //列表页面
        public static async Task<(IEnumerable<dynamic>, int)> GetCG_Bidder(CG_BidderQuerry querry)
        {
            string str = "and   1=1 ";
            if (!string.IsNullOrEmpty(querry.zbmc) && querry.zbmc != "string")
            {
                str += "and zbmc like '%" + querry.zbmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cgfs) && querry.cgfs != "string")
            {
                str += "and cgfs = '" + querry.cgfs + "'";
            }
            if (!string.IsNullOrEmpty(querry.zbfs) && querry.zbfs != "string")
            {
                str += " and zbfs = '" + querry.zbfs + "'";
            }
            if (querry.ysje1 != null || querry.ysje2 != null)
            {
                if (querry.ysje2 >= querry.ysje1)
                {

                    str += " and (ysje between '" + querry.ysje1 + "' and '" + querry.ysje2 + "')";
                }
                else
                {
                    str += " and (ysje between 0 and 0)";
                }
            }
            if (!string.IsNullOrEmpty(querry.cgxmmc) && querry.cgxmmc != "string")
            {
                str += "and cgxmmc like '%" + querry.cgxmmc + "%'";
            }
           


            
            if (!string.IsNullOrEmpty(querry.bdmc) && querry.bdmc != "string")
            {
                str += "and bdmc like '%" + querry.bdmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.zbdw) && querry.zbdw != "string")
            {
                str += "and zbdw like '%" + querry.zbdw + "%'";
            }
            if (!string.IsNullOrEmpty(querry.zt) && querry.zt != "string")
            {
                string status = "";
                if (querry.zt == "待提交")
                {
                    status = "1";
                }
                else if (querry.zt == "已驳回")
                {
                    status = "4";

                }
                else if (querry.zt == "已作废")
                {
                    status = "5";

                }
                else if (querry.zt == "待审核")
                {
                    status = "2";

                }
                else if (querry.zt == "审核中")
                {
                    status = "9";

                }
                else if (querry.zt == "已通过")
                {
                    status = "3";

                }

                else
                {
                    status = "0";
                }
                str += " and zt = '" + status + "'";
            }
            string sql = @"select * from vw_pur_bidder where (bmdm in " + querry.DepartID + " )" + str;
            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);
        }

        public static async Task<DataTable> GetCG_Bidder_zbsq(string djbm)
        {


            string sql = "select a.djbm,a.zbmc,b.cgfs,a.zbfs,a.ysje,a.dlzjjg,a.zbfzr,a.cgxmbm,b.cgxmmc,a.bdid,a.bdmc  from pur_invite a inner join pur_approval b on a.cgxmbm = b.cgxmbm and a.bdid = (select bdid from pur_bidder where djbm='" + djbm+"'); ";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> GetCG_Bidder_tbdw(string djbm)
        {


            string sql = "select * from  pur_bidder_tbdw  where  djbm='" + djbm + "' ;";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }
        public static async Task<DataTable> GetCG_Bidder_zbxx(string djbm)
        {


            string sql = "select  djbm, bdid, bdmc, cgxmbm, cgxmmc, zbdw, zbje, zbsj, bz, tjr, tjsj, bmdm from pur_bidder where djbm='" + djbm + "' ;";

            return await new RepositoryFactory().BaseRepository().FindTable(sql, null);

        }

        //选择招标申请
        public static async Task<(IEnumerable<dynamic>, int)> SelectCG_Invite(CG_InviteQuerry querry)
        {
            string str = "and 1=1 ";
            if (!string.IsNullOrEmpty(querry.zbmc) && querry.zbmc != "string")
            {
                str += "and zbmc like '%" + querry.zbmc + "%'";
            }
            if (querry.ysje1 != null || querry.ysje2 != null)
            {
                if (querry.ysje2 >= querry.ysje1)
                {

                    str += " and (ysje between '" + querry.ysje1 + "' and '" + querry.ysje2 + "')";
                }
                else
                {
                    str += " and (ysje between 0 and 0)";
                }
            }
            if (!string.IsNullOrEmpty(querry.cgxmmc) && querry.cgxmmc != "string")
            {
                str += "and cgxmmc like '%" + querry.cgxmmc + "%'";
            }
            if (!string.IsNullOrEmpty(querry.cgfs) && querry.cgfs != "string")
            {
                str += "and cgfs = '" + querry.cgfs + "'";
            }


            if (!string.IsNullOrEmpty(querry.zbfs) && querry.zbfs != "string")
            {
                str += " and zbfs = '" + querry.zbfs + "'";
            }
            if (!string.IsNullOrEmpty(querry.bdmc) && querry.bdmc != "string")
            {
                str += "and bdmc like '%" + querry.bdmc + "%'";
            }
            
            string sql = "select * from vw_pur_invite where (bmdm in " + querry.DepartID + " ) and zt='3' and zbjd <>'招标完成' and bdid not in (select bdid from pur_bidder)  " + str;

            bool isAsc = true;
            if (querry.Sort.ToUpper() != "ASC")
            {
                isAsc = false;
            }
            //return await new RepositoryFactory().BaseRepository().FindTable(sql, null, querry.SortString, isAsc, querry.PageSize, querry.Current);
            return await new RepositoryFactory().BaseRepository().FindList(sql, null, querry.SortString, isAsc, querry.Size, querry.Current);

        }

        //存草稿、提交
        public static async Task InsertCG_Bidder(CG_Bidder_Sub zb)
        {

            string sql = "";
            if (zb.zbxx.listid == "1")
            {
                sql = @"insert into pur_bidder(djbm,bdid,bdmc,cgxmbm,cgxmmc,zbdw,zbje,zbsj,bz,tjr,tjsj,zt,bmdm) values ('"+zb.zbxx.djbm+"','"+zb.zbxx.bdid+"','"+zb.zbxx.bdmc+"','"+zb.zbxx.cgxmbm+"','"+zb.zbxx.cgxmmc+"','"+zb.zbxx.zbdw+"','"+zb.zbxx.zbje+"','"+zb.zbxx.zbsj+"','"+zb.zbxx.bz+"','"+zb.zbxx.tjr+"','"+zb.zbxx.tjsj+"','"+zb.zbxx.zt+"','"+zb.zbxx.bmdm+"');  ";


            }
            else
            {
                sql = "update pur_bidder set bdid='"+zb.zbxx.bdid + "',bdmc='"+zb.zbxx.bdmc + "',cgxmbm='"+zb.zbxx.cgxmbm + "',cgxmmc='"+zb.zbxx.cgxmmc + "',zbdw='"+zb.zbxx.zbdw + "',zbje='"+zb.zbxx.zbje + "',zbsj='"+zb.zbxx.zbsj + "',bz='"+zb.zbxx.bz + "',tjr='"+zb.zbxx.tjr + "',tjsj='"+zb.zbxx.tjsj + "',zt='"+zb.zbxx.zt + "',bmdm='"+zb.zbxx.bmdm+"'  where djbm='" + zb.zbxx.djbm + "'  ; ";

            }
            sql += "update pur_bidder set zbsj=null where zbsj='1900-01-01 00:00:00.000' and djbm='"+zb.zbxx.djbm+"' ; ";
            await DeleteCG_Bidder_tbdw(zb.zbxx.djbm);
            foreach (CG_Bidder_tbdw dw in zb.tbdw)
            {
                await InsertCG_Bidder_tbdw(dw, zb.zbxx.djbm);
            }
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }

        public static async Task DeleteCG_Bidder_tbdw(string djbm)
        {

            string sql = "delete pur_bidder_tbdw where djbm='" + djbm + "'; ";


            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }

        public static async Task InsertCG_Bidder_tbdw(CG_Bidder_tbdw dw, string djbm)
        {
            
            string sql = "insert into pur_bidder_tbdw(djbm,dwmc,shxydm,qylx,fddbr,fddbrsfz,dbr,dbrsfz,lxdh,bz,tbj) values('"+djbm+"','"+dw.dwmc+"','"+dw.shxydm+"','"+dw.qylx+"','"+dw.fddbr+"','"+dw.fddbrsfz+"','"+dw.dbr+"','"+dw.dbrsfz+"','"+dw.lxdh+"','"+dw.bz+"','"+dw.tbj+"') ; ";


            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }

        //删除中标管理
        public static async Task DeleteCG_Bidder(string strid)
        {

            string sql = "delete pur_bidder where djbm in (" + strid + ") ; ";
            sql += "delete pur_bidder_tbdw where djbm in (" + strid + ") ; ";

            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }


        //审批回调
        public static async Task UpdateCG_Bidderzt(string djbm, string zt)
        {

            string sql = "update pur_bidder set zt='" + zt + "' where djbm='" + djbm + "' ";
            if (zt == "3")
            {
                sql += "update pur_invite set zbjd='招标完成' where bdid=(select bdid from pur_bidder where djbm='" + djbm + "') ";
            }
            else
            {
                sql += "update pur_invite set zbjd='招标中' where bdid=(select bdid from pur_bidder where djbm='" + djbm + "') ";
            }
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);

        }
        #endregion
    }
}
